﻿using System;
using QDT.Core.Members;

namespace QDT.Core.Domain
{
    public class UserCarry : Entity
    {
        /// <summary>
        /// 用户ID
        /// </summary>
        public int UserId { get; set; }
        /// <summary>
        /// 提现金额
        /// </summary>
        public decimal Money { get; set; }
        /// <summary>
        /// 手续费
        /// </summary>
        public decimal Fee { get; private set; }
        /// <summary>
        /// 银行ID
        /// </summary>
        public int BankId { get; set; }
        /// <summary>
        /// 银行卡号
        /// </summary>
        public string BankCard { get; set; }
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreateTime { get; set; }
        /// <summary>
        /// 修改时间
        /// </summary>
        public DateTime? UpdateTime { get; set; }
        /// <summary>
        /// 状态 : 0申请1成功2驳回6提交通联-1异常
        /// </summary>
        public int Status { get; private set; }
        /// <summary>
        /// 失败原因
        /// </summary>
        public string Msg { get; set; }
        /// <summary>
        /// 操作备注
        /// </summary>
        public string Desc { get; set; }
        /// <summary>
        /// 用户真实姓名
        /// </summary>
        public string RealName { get; set; }
        /// <summary>
        /// 开户行网点
        /// </summary>
        public string BankZone { get; set; }
        /// <summary>
        /// 国家
        /// </summary>
        public int RegionLv1 { get; set; }
        /// <summary>
        /// 省
        /// </summary>
        public int RegionLv2 { get; set; }
        /// <summary>
        /// 市县
        /// </summary>
        public int RegionLv3 { get; set; }
        /// <summary>
        /// 区镇
        /// </summary>
        public int RegionLv4 { get; set; }

        public UserCarry()
        {
            CreateTime = DateTime.Now;
            UpdateTime = null;
            Status = 0;
        }

        public UserCarry(User user, decimal money, int bankId, string bankCard, string bankZone, int r1, int r2, int r3, int r4) : this()
        {
            UserId = user.ID;
            RealName = user.RealName;
            Money = money;
            BankId = bankId;
            BankCard = bankCard;
            BankZone = bankZone;
            RegionLv1 = r1;
            RegionLv2 = r2;
            RegionLv3 = r3;
            RegionLv4 = r4;
            SetFee(money);
        }

        private void SetFee(decimal money)
        {
            Fee = money/100;
        }

        public void SetStatus(int status)
        {
            if (Status != 0 && status ==6)
            {
                throw new Exception("无效状态");
            }

            if (Status == 1 || Status == 2)
            {
                throw new Exception("当前状态不能更改");
            }

            Status = status;
        }

    }
}
